﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace TCL.FUNC
{
    public class DataTableEx
    {

        #region "GetDataGridView"
        DataTable GetDataTable(GridView dtg)
        {
            DataTable dt = new DataTable();

            // add the columns to the datatable            
            if (dtg.HeaderRow != null)
            {

                for (int i = 0; i < dtg.HeaderRow.Cells.Count; i++)
                {
                    dt.Columns.Add(dtg.HeaderRow.Cells[i].Text);
                }
            }

            //  add each of the data rows to the table
            foreach (GridViewRow row in dtg.Rows)
            {
                DataRow dr;
                dr = dt.NewRow();
                dr[1] = ((TextBox)row.Cells[1].FindControl("txtsName")).Text;
                dr[2] = ((TextBox)row.Cells[2].FindControl("txtsContent")).Text;
                //for (int i = 0; i < row.Cells.Count; i++)
                //{
                //    dr[i] = row.Cells[i].Text.Replace(" ", "");
                //}
                dt.Rows.Add(dr);
            }
            return dt;
        }

        //List<XML_SEOEO> GetListObject(GridView dtg)
        //{
        //    List<XML_SEOEO> lstobj = new List<XML_SEOEO>();
        //    XML_SEOEO obj;
        //    foreach (GridViewRow row in dtg.Rows)
        //    {
        //        obj = new XML_SEOEO();
        //        obj.sName = ((TextBox)row.Cells[1].FindControl("txtsName")).Text;
        //        obj.sContent = ((TextBox)row.Cells[2].FindControl("txtsContent")).Text;
        //        obj.sType = ((DropDownList)row.Cells[4].FindControl("ddlsType")).SelectedValue;
        //        lstobj.Add(obj);
        //    }
        //    return lstobj;
        //}
        #endregion
    }
}
